<include file="public:header" />
<include file="public:left" />
<form method="post" action="{:url('api/coupon/createCard')}" enctype="multipart/form-data" id="brandForm">
	<section>
		<h2><strong>添加会员卡</strong><a style="float: right" href="javascript:void(0)" onclick="history.go(-1)">返回上一页</a></h2>
		<ul class="ulColumn2">
			<li>
				<span class="item_name" style="width:120px;">名称：</span>
				<input type="text" class="textbox textbox_295 name" name="name" value="" placeholder="卡券名字"/>
			</li>
			<li>
				<span class="item_name" style="width:120px;">优惠券logo：</span>
				<input type="file" id="logo" name="logo" />
			</li>
			<li>
				<span class="item_name" style="width:120px;">优惠金额：</span>
				<input type="text" class="textbox textbox_295 money" value="500" name="money" />
			</li>
			<li>
				<span class="item_name" style="width:120px;">发放数量：</span>
				<input type="text" class="textbox textbox_295 quantity" value="500" name="quantity" placeholder="上限为100000000"/>
			</li>
			<li>
				<span class="item_name" style="width:120px;">每人限领多少：</span>
				<input type="text" class="textbox textbox_295 get_limit" value="5" name="get_limit"/>
			</li>
			<li>
				<span class="item_name" style="width:120px;">标题：</span>
				<input type="text" class="textbox textbox_295 title" name="title" value="400元代金券" placeholder="9个汉字以内，如：400元优惠券"/>
			</li>
			<li>
				<span class="item_name" style="width:120px;">使用提醒：</span>
				<input type="text" class="textbox textbox_295 notice" value="订房时可用" name="notice" placeholder="16个汉字以内，如：订房时可用"/>
			</li>
			<li>
				<span class="item_name" style="width:120px;">描述：</span>
				<textarea class="textbox des textbox_295" style="height: 50px;" name="des">本优惠券解释权归七彩虹酒店所有</textarea>
			</li>
			<li>
				<span class="item_name" style="width:120px;">类型：</span>
				<select name="status" id="" class="textbox textbox_295 status" style="height: 35px">
					<option value="1">订房用</option>
					<option value="2">游泳用</option>
					<option value="3">健身用</option>
				</select>
			</li>
			<li>
				<span class="item_name" style="width:120px;">条件：</span>
				<select name="type" id="" class="textbox textbox_295 type" style="height: 35px">
					<option value="1">任何会员都可领</option>
					<option value="2">金卡会员及以上可领</option>
					<option value="3">铂金卡会员及以上可领</option>
					<option value="4">黑金卡会员可领</option>
				</select>
			</li>
			<li>
		        <span class="item_name" style="width:120px;">开始日期：</span>
	        	<input type="text" class="textbox textbox_295 start_date" name="start_date" id="start_date" placeholder="开始日期..."/>
            </li>
            <li>
		        <span class="item_name" style="width:120px;">结束日期：</span>
	        	<input type="text" class="textbox textbox_295 end_date" name="end_date" id="end_date" placeholder="结束日期..."/>
            </li>
			<li>
				<span class="item_name" style="width:120px;">可用日期：</span>
				<volist name="arr" id="vo">
					<input value="{$vo} " class="textbox week" style="border: 1px solid #F4F4F4;width: 70px;text-align: center;cursor: pointer;color: #fff;background-color: #0066CC;" readonly="readonly"/>
					<input type="hidden" class="pd" value="2" />
				</volist>
			</li>
			<li>
		        <span class="item_name" style="width:120px;">服务电话：</span>
	        	<input type="text" class="textbox textbox_295 tel" value="123456789" name=""/>
            </li>
			<li>
				<span class="item_name" style="width:120px;"></span>
				<input type="button" class="link_btn" value="提交" />
			</li>
		</ul>
	</section>
</form>
<script type="text/javascript" src="__STATIC__/admin/js/ajaxfileupload.js"></script>
<script type="text/javascript" src='__STATIC__/admin/js/laydate/laydate.js'></script>
<script type="text/javascript">
	$(document).ready(function() {
		laydate({
			elem: '#start_date', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
			format: 'YYYY/MM/DD hh:mm:ss',
			istime: true,
			event: 'focus' //响应事件。如果没有传入event，则按照默认的click
		});
		laydate({
			elem: '#end_date', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
			format: 'YYYY/MM/DD hh:mm:ss',
			istime: true,
			event: 'focus' //响应事件。如果没有传入event，则按照默认的click
		});
		$('.money').blur(function(){
		    var reg = /^\d+(\.\d+)?$/;
		    if(reg.test($(this).val())==false){
				$(this).val('');
		    }
	    })
		$('.quantity').blur(function(){
		    var reg = /^\d+(\.\d+)?$/;
		    if(reg.test($(this).val())==false){
				$(this).val('');
		    }
	    })
		$('.get_limit').blur(function(){
		    var reg = /^\d+(\.\d+)?$/;
		    if(reg.test($(this).val())==false){
				$(this).val('');
		    }
	    })
		$('.week').click(function(){
			if($(this).next().val()==1){
				$(this).css("background-color","#0066CC");
				$(this).css("color","#fff");
				$(this).next().val(2);
			}else if($(this).next().val()==2){
				$(this).css("background-color","#fff");
				$(this).css("color","#000");
				$(this).next().val(1);
			}
		})
		
		$(".link_btn").click(function() {
		    var i='';
			$('.pd').each(function(){
				if($(this).val()==2){
					i+=$(this).prev().val()+',';
				}
			})
			i=i.substring(0, i.lastIndexOf(',')); 
			if(i==''){
				alert('最少要选择一天可用');
				return false;
			}
			var name          = $('.name').val();
			var title         = $('.title').val();
			var notice        = $('.notice').val();
			var des           = $('.des').val();
			var status        = $('.status').val();
			var type          = $('.type').val();
			var money         = $('.money').val();
			var quantity      = $('.quantity').val();
			var service_phone = $('.tel').val();
			var end_date      = $('.end_date').val();
			var start_date    = $('.start_date').val();
			var get_limit     = $('.get_limit').val();
			var reg = /^\d+(\.\d+)?$/;
		    if(reg.test(money)==false){
				alert('优惠金额填写有误');
				return false;
		    }
		    if(reg.test(get_limit)==false){
				alert('限领金额填写有误');
				return false;
		    }
		    if(reg.test(quantity)==false){
				alert('发放数量填写有误');
				return false;
		    }
			if(name==''||title==''||des==''||status==''||money==''||type==''||get_limit==''||quantity==''){
				alert('请完善数据');
				return false;
			}
			
			$.ajaxFileUpload
	        ({   
	        	type:"post",
	            url:"{:url('api/coupon/createCard')}", //用于文件上传的服务器端请求地址
	            secureuri: false, //是否需要安全协议，一般设置为false
	            fileElementId:'logo',//文件选择框的id属性
	            dataType:'json',
	            data:{
	            	name:name,
	            	title:title,
	            	notice:notice,
	            	des:des,
	            	status:status,
	            	type:type,
	            	money:money,
	            	quantity:quantity,
	            	week:i,
	            	service_phone:service_phone,
	            	get_limit:get_limit,
	            	start_date:start_date,
	            	end_date:end_date
	            },
	            success:function(data){
	            	var pd   = data['code'];
	            	if(pd==1){     
	            		alert("创建优惠券成功");
	                	location.href="{:url('coupon/lists')}";
	                }else{
	                	alert("创建优惠券失败");
	                }
	   
	            }
	        })
	        
		});
		
	});
</script>

</div>
</section>
</body>

</html>